package com.timeserver.netty.chapter2;

import com.sun.corba.se.spi.activation.Server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by zhaoyong on 16/5/4.
 */
public class TimeServer {
    public static void main(String[] args) {
        int port = 8080;
        Socket socket = null;
        if (args != null && args.length > 0) {
            port = Integer.valueOf(args[0]);
        }
        ServerSocket socketServer = null;
        try {
            socketServer = new ServerSocket(port);
            ThreadServerHandlerExecutePool threadServerHandlerExecutePool = new ThreadServerHandlerExecutePool(50, 10000);
            while (true) {
                socket = socketServer.accept();
                threadServerHandlerExecutePool.execute(new TimeServerHandler(socket));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                socketServer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            socketServer = null;
        }
    }
}
